package com.pay.allmoney.service.impl;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.pay.allmoney.dto.AlipayConfig;
import com.pay.allmoney.service.AliPayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class AliPayServiceImpl implements AliPayService {


    @Override
    public AlipayClient getAliPayClient() {
        AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
        return alipayClient;
    }

    @Override
    public AlipayTradePagePayRequest getAliPayRequest() {
        log.info("return_url:{},notify_url:{}",AlipayConfig.return_url,AlipayConfig.notify_url);
        AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
        alipayRequest.setReturnUrl(AlipayConfig.return_url);
        alipayRequest.setNotifyUrl(AlipayConfig.notify_url);
        return alipayRequest;
    }
}
